<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.fick.hibernate.model.*"%>
<%@ page import="com.fick.hibernate.dao.*"%>
<%@page import="com.fick.tools.SystemLogger"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@ include file="../tld/tlds.jsp"%>
<%
   Admin admins = (Admin)request.getSession().getAttribute("admin");
 %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="images/jiahao.css" rel="stylesheet" type="text/css">
<script language="JavaScript" src="js/meihuaxue.js"></script>
		<script language="javaScript" src="js/prototype.js"></script>
		<script type="text/javascript" src="js/submit.js"></script>
</head>

<body>
<table width="100%"  height="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="100%" align="center" valign="top" background="images/main_bj.gif" bgcolor="#FBFCFD">

<%   VodDAO dao=new VodDAO();
    AdminQxDAO qxdao=new AdminQxDAO();
Admin admin=(Admin)request.getSession().getAttribute("admin");		   
int pagesize=10;
int currpage=1;
//总的页数
int totalPage = 1;
//总共有的记录数
int totalCount = 1;
List vodlist=null;
String channelid=request.getParameter("channelid");

if (admin.getRole().getId() == 3 || admin.getRole().getId() == 5 ) 
    {       if(channelid==null||channelid.equals("null"))
		    {
    		totalCount=dao.count(Vod.class,"");
		    }
            else
            {
        		totalCount=dao.count(Vod.class,"where channel.channelId="+channelid);
            }
    }
else
    {
   if(channelid==null||channelid.equals("null"))
		    {
		totalCount=dao.count(Vod.class,"where admin.adminId="+admin.getAdminId());
		    }
	      else
	      {
	  		totalCount=dao.count(Vod.class,"where admin.adminId="+admin.getAdminId()+" and channel.channelId="+channelid);
	      }
	}
//得到总的页数
if(totalCount%pagesize==0){
	totalPage = totalCount/pagesize;
}else{
	totalPage = totalCount/pagesize+1;
}
//判断是否是传过来页数
if(request.getParameter("currpage") != null){
   currpage = Integer.parseInt(request.getParameter("currpage"));
   if(currpage<1){
     currpage=1;
    }
   if(currpage >totalPage){
     currpage = totalPage;
   }
} 
if (admin.getRole().getId() == 3 || admin.getRole().getId() == 5 ) 
    {       if(channelid==null||channelid.equals("null"))
		    {
			vodlist=dao.findPageBySql(Vod.class,currpage,pagesize,"order by addTime desc,id desc");
		    }
            else
            {
            	vodlist=dao.findPageBySql(Vod.class,currpage,pagesize,"where channel.channelId="+channelid+" order by addTime desc,id desc");
            }
    }
else
    {
   if(channelid==null||channelid.equals("null"))
		    {
			vodlist=dao.findPageBySql(Vod.class,currpage,pagesize,"where admin.adminId="+admin.getAdminId()+" order by addTime desc,id desc");
		    }
	      else
	      {
        	vodlist=dao.findPageBySql(Vod.class,currpage,pagesize,"where admin.adminId="+admin.getAdminId()+" and  channel.channelId="+channelid+" order by addTime desc,id desc");
	      }
	}
%>

    
      <table width="98%" border="0" cellpadding="0" cellspacing="1" bgcolor="#D7DFE1">
        <tr>
          <td width="4%" height="25" align="center" valign="middle" background="images/main_t_bj.gif" bgcolor="#FFFFFF" class="ts_lmdh">选择</td>
          <td width="35%" height="25" align="center" valign="middle" background="images/main_t_bj.gif" bgcolor="#FFFFFF" class="ts_lmdh">视频名称</td>
          <td width="15%" height="25" align="center" valign="middle" background="images/main_t_bj.gif" bgcolor="#FFFFFF" class="ts_lmdh">发布时间</td>
          <td width="8%" height="25" align="center" valign="middle" background="images/main_t_bj.gif" bgcolor="#FFFFFF" class="ts_lmdh">作者</td>
          <td width="15%" height="25" align="center" valign="middle" background="images/main_t_bj.gif" bgcolor="#FFFFFF" class="ts_lmdh">操作</td>
        </tr>
        <%
        Vod vod;Admin admin2;
	    SimpleDateFormat   format   =   new   SimpleDateFormat("yyyy-MM-dd HH:mm");
			for(int i = 0 ; i < vodlist.size(); i++){
				vod = (Vod)vodlist.get(i);
		%>
		<tr>
          <td width="4%" height="25" align="center" valign="middle" bgcolor="#FFFFFF">
		 <input type="checkbox" name="MyCheckBox" id="MyCheckBox" value="<%=vod.getId() %>" />
		  </td>
          <td width="35%" height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px">
		  <%
	
			if(vod.getName().length()>16){										        	
			   out.print(vod.getName().substring(0,16)+"...");
			 }else{
				out.print(vod.getName());
			 }
		   %>
		  
		  </td>
          <td width="15%" height="25" align="center" valign="middle" bgcolor="#FFFFFF"><%=format.format(vod.getAddTime())%></td>
          <% admin2=vod.getAdmin(); 
          %>
          <td width="8%" height="25" align="center" valign="middle" bgcolor="#FFFFFF"><%=admin2.getAdminName()%></td>
          
          <td width="15%" height="25" align="center" valign="middle" bgcolor="#FFFFFF">
		  <a href="addVod.jsp?id=<%=vod.getId() %>">修改</a>&nbsp;
		<a href="<%=request.getContextPath()%>/admin/vod.do?method=delById&id=<%=vod.getId() %>" onclick="return confirm('确定要删除吗？删除之后无法恢复')">删除</a>
		  </td>
        </tr>
		<%
			}
		%>
		
	
        
		
      </table>
	    <table width="98%" border="0" cellspacing="0" cellpadding="0">
	  	<tr>
			 <td height="45" align="left" valign="middle">
			 <input type="button" name="selectAlls" id="selectAlls" value="全选" onclick="return selectAll()" />
			 <input type="button" name="noSelectAll" id="noSelectAll" value="反选" onclick="return selectOthers();" />
			<input type="button" name="cancelSelects" id="cancelSelects" value="取消选择" onclick="return cancelSelect();" />
			<input type="button" name="delAlls" id="delAlls" value="删除所选" onclick="return delAll('vod.do?method=delAll&str=');"/>
				
										   	  	
			</td>
		</tr>
	  </table>
      <table width="98%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td height="45" align="center" valign="middle">
		  共有［<%=totalCount %>］条 当前是第［<%=currpage %>/<%=totalPage %>］页 [<a href="treeVod.jsp?channelid=<%=channelid %>&currpage=1" class="page">首页</a>][<a href="treeVod.jsp?channelid=<%=channelid %>&currpage=<%=currpage-1 %>" class="page">上一页</a>][<a href="treeVod.jsp?channelid=<%=channelid %>&currpage=<%=currpage+1 %>" class="page">下一页</a>][<a href="treeVod.jsp?channelid=<%=channelid %>&currpage=<%=totalPage %>" class="page">尾页</a>]
		  到第
            <select name="select" onChange="gopage(this)">
			<%
				for(int i = 0;i<totalPage ; i++)
				{
					out.print("<option value='treeVod.jsp?channelid="+channelid +"&currpage="+(i+1)+"'>"+(i+1)+"</option>");
				}
			%>
			
            </select>
          页
		 </td>
        </tr>
      </table>
</table>
</body>
</html>
<script type="text/javascript">
<!--
var message = "<%=session.getAttribute("message")%>";
if(message!=null && message!="null" && message !=""){
   alert(message);
  }
 function gopage(selected)
 {
 	window.open(selected.value,"_self");
 }
//-->
</script>
<%
	session.removeAttribute("message");
%>